#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
using namespace std;

//以下做法有点小题大做了，看了别人的做法是直接对字符串进行处理
//而且字符串也很好排序，写出来代码很简洁

int tosecond(int h, int m, int s)
{
    return h * 60 * 60 + m * 60 + s;
}

struct TIME
{
    int h, m, s;
    bool operator>(const TIME &t) const
    {
        int s1 = tosecond(h, m, s);
        int s2 = tosecond(t.h, t.m, t.s);
        return s1 > s2;
    }
};

struct AREA
{
    TIME from, to;
    bool operator>(const AREA &a) const
    {
        return this->from > a.from;
    }
};

priority_queue<AREA, vector<AREA>, greater<AREA>> qu;
priority_queue<AREA, vector<AREA>, greater<AREA>> ans;

TIME totime(int second)
{
    TIME a;
    a.h = second / (60 * 60);
    second %= (60 * 60);
    a.m = second / 60;
    second %= 60;
    a.s = second;
    return a;
}

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        int h1, m1, s1, h2, m2, s2;
        scanf("%02d:%02d:%02d - %02d:%02d:%02d", &h1, &m1, &s1, &h2, &m2, &s2);
        qu.push({{h1, m1, s1}, {h2, m2, s2}});
    }
    int head = 0;
    while (!qu.empty())
    {
        AREA top = qu.top();
        qu.pop();
        int second1 = tosecond(top.from.h, top.from.m, top.from.s);
        int second2 = tosecond(top.to.h, top.to.m, top.to.s);
        if (second1 != head)
        {
            ans.push({totime(head), totime(second1)});
        }
        head = second2;
    }
    if (head != (60 * 60 * 24 - 1))
    {
        ans.push({totime(head), totime(60 * 60 * 24 - 1)});
    }
    while (!ans.empty())
    {
        TIME t1 = ans.top().from;
        TIME t2 = ans.top().to;
        ans.pop();
        printf("%02d:%02d:%02d - %02d:%02d:%02d\n", t1.h, t1.m, t1.s, t2.h, t2.m, t2.s);
    }
    return 0;
}